package com.mall.controller;

import com.mall.common.Result;
import com.mall.entity.Cart;
import com.mall.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理端购物车管理接口
 */
@RestController
@RequestMapping("/admin/cart")
public class AdminCartController {

    @Autowired
    private CartService cartService;

    // 1. 分页查询购物车列表
    @GetMapping("/list")
    public Result<List<Cart>> list() {
        // 可扩展分页参数
        List<Cart> carts = cartService.listAll();
        return Result.success(carts);
    }

    // 2. 查询购物车项详情
    @GetMapping("/{id}")
    public Result<Cart> getById(@PathVariable Long id) {
        Cart cart = cartService.getById(id);
        return Result.success(cart);
    }

    // 3. 新增购物车项
    @PostMapping
    public Result<Void> add(@RequestBody Cart cart) {
        cartService.add(cart);
        return Result.success();
    }

    // 4. 修改购物车项
    @PutMapping("/{id}")
    public Result<Void> update(@PathVariable Long id, @RequestBody Cart cart) {
        cart.setId(id);
        cartService.update(cart);
        return Result.success();
    }

    // 5. 删除购物车项
    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Long id) {
        cartService.delete(id);
        return Result.success();
    }
}